package serven;

import static util.Print.print;

/**
 * Created by ab on 2016/11/2.
 * 从Detergent中继承产生一个新的类。覆盖scrub()并添加一个名为sterilize()的新方法。
 */

class Cleanser{
    private String s="Cleanser";
    public void append(String a){s+=a;}
    public void dilute(){append("dilute ");}
    public void apply(){append("apply ");}
    public void scrub(){append("scrub ");}
    public String toString(){
        return s;
    }
    public static void main(String[] args){
        Cleanser x=new Cleanser();
        x.dilute();
        x.apply();
        x.scrub();
        print(x);
    }
}

class Detergent extends Cleanser{
    //Change a method
    public void scrub(){
        append("Detergent scrub()");
        super.scrub();//Call base-class version
    }
    //Add method to the interface
    public void foam(){
        append(" foam()");
    }
}

class NDetergent extends Detergent{
    public void scrub(){
        append("new scrub()");
        super.scrub();//Call base-class version
    }
}

public class task2 {
    public static void main(String[] args){
        NDetergent Nd= new NDetergent();
        Nd.dilute();
        Nd.apply();
        Nd.scrub();
        print(Nd);
        print("Testing base class:");
        Cleanser.main(args);
    }
}
